package com.hmall.item;

import com.hmall.item.es.ESDataBulk;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import static com.hmall.item.es.ESDataBulk.close;
import static com.hmall.item.es.ESDataBulk.connect;

/**
 * @author zzw
 * @date 2025/6/24
 * @description 导入数据到ES，只需运行一次，后续数据更新请自行处理
 */
@SpringBootApplication //运行一次后将此注解注释掉
public class ESCommandLineRunner implements CommandLineRunner {
    private final ESDataBulk esDataBulk;

    public ESCommandLineRunner(ESDataBulk esDataBulk) {
        this.esDataBulk = esDataBulk;
    }

    public static void main(String[] args) {
        SpringApplication.run(ESCommandLineRunner.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        String host = "192.168.101.68";
        int port = 9200;
        connect(host, port);
        esDataBulk.esBulk();
        close();
        // 退出程序
        System.exit(0);
    }
}
